package com.tarena.lbs.coupon.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.coupon.dao.mapper.UserCouponsMapper;
import com.tarena.lbs.coupon.dao.repository.UserCouponsRepository;
import com.tarena.lbs.coupon.pojo.po.UserCouponsPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class UserCouponsRepositoryImpl implements UserCouponsRepository {
    @Autowired
    private UserCouponsMapper  userCouponsMapper;

    @Override
    public Long count(QueryWrapper queryWrapper) {
        log.debug("查询用户优惠券信息", queryWrapper);
        Long count = userCouponsMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public void save(UserCouponsPO po) {
        log.debug("保存用户优惠券信息", po);
        userCouponsMapper.insert(po);
        log.debug("保存用户优惠券信息成功");
    }

    @Override
    public List<UserCouponsPO> list(QueryWrapper<UserCouponsPO> queryWrapper) {
        log.debug("查询用户优惠券信息", queryWrapper);
        List<UserCouponsPO> list = userCouponsMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public UserCouponsPO getOne(QueryWrapper<UserCouponsPO> queryWrapper) {
        log.debug("查询用户优惠券信息", queryWrapper);
        UserCouponsPO userCouponsPO = userCouponsMapper.selectOne(queryWrapper);
        return userCouponsPO;
    }
}
